package com.chefu.order.controller;


import com.chefu.common.pojo.PageResult;
import com.chefu.common.pojo.R;
import com.chefu.order.pojo.AutoPartsOrderDetail;
import com.chefu.order.pojo.vo.AutoPartsDetailVo;
import com.chefu.order.pojo.vo.AutoPartsOrderPageParamVo;
import com.chefu.order.pojo.vo.AutoPartsOrderPageVo;
import com.chefu.order.service.AutoPartsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author goodgoodstudy
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/order/autoparts")
public class AutoPartsOrderController {

    @Autowired
    private AutoPartsOrderService partsOrderService;

    /**
     * 通过分页和查询条件，获取配件订单列表
     * @param pageNo 当前页
     * @param pageSize 页面大小
     * @param paramVo 查询参数
     * @return 页面查询结果集
     */
    @GetMapping("/page")
    public R getOrderPage(@RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo,
                          @RequestParam(value = "pageSize",defaultValue = "20")Integer pageSize,
                          @Valid AutoPartsOrderPageParamVo paramVo
                          ){
        PageResult<AutoPartsOrderPageVo> pageResult = partsOrderService.getOrderPage(pageNo,pageSize,paramVo);
        return R.ok().data("pageResult",pageResult);
    }

    @GetMapping("/{orderId}")
    public R getOrderDetail(@PathVariable("orderId") Long orderId){
        AutoPartsDetailVo orderDetail = partsOrderService.getOrderDetail(orderId);
        return R.ok().data("partOrderVo",orderDetail);
    }

}

